//
//  AppDelegate.m
//  QQ
//
//  Created by nhope on 2017/4/14.
//  Copyright © 2017年 xiaopin. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

/// QQ登录后的主面板窗口控制器
@property (nonatomic, strong) NSWindowController *qqMainWindowController;

@end

@implementation AppDelegate

#pragma mark - <NSApplicationDelegate>

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(loginSuccessNotification:)
                                                 name:kLoginSuccessNotification
                                               object:nil];
}


- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
    if (nil != _qqMainWindowController) {
        return NO;
    }
    return YES;
}

- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag {
    if (nil != _qqMainWindowController) {
        [_qqMainWindowController showWindow:self];
    }
    return YES;
}

#pragma mark - Actions

- (void)loginSuccessNotification:(NSNotification *)sender {
    if (nil == _qqMainWindowController) {
        NSStoryboard *storyboard = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
        _qqMainWindowController = [storyboard instantiateControllerWithIdentifier:@"QQMainWindowController"];
    }
    [_qqMainWindowController showWindow:self];
    [_qqMainWindowController.window center];
}


@end
